package com.qfedu.mbti.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qfedu.mbti.config.RedisKeyConfig;
import com.qfedu.mbti.dao.UserLogDao;
import com.qfedu.mbti.entity.UserLog;
import com.qfedu.mbti.service.UserLogService;
import com.qfedu.mbti.vo.R;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 用户日志表(UserLog)表服务实现类
 *
 * @author makejava
 * @since 2024-11-04 11:43:41
 */
@Service("userLogService")
@RequiredArgsConstructor
public class UserLogServiceImpl implements UserLogService {
    private final UserLogDao dao;
    private final StringRedisTemplate stringRedisTemplate;

    @Override
    public R queryByUid(String token) {
        //1.条件
        LambdaQueryWrapper<UserLog> wrapper=new LambdaQueryWrapper<>();
        wrapper.orderByDesc(UserLog::getCreateTime);
        //2.获取用户ID
        String uid=stringRedisTemplate.opsForValue().get(RedisKeyConfig.USER_TOKEN+token);
        if(StringUtils.hasLength(uid)){
            wrapper.eq(UserLog::getUid,uid);
        }
        //3.返回
        return R.ok(dao.selectList(wrapper));
    }
}

